package lsem.eclipse.vdf.ui.navigator;

import lsem.eclipse.vdf.ui.handler.VDFCommonNavigatorHandler;

import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.navigator.CommonNavigator;

public class VDFCommonNavigatorView extends CommonNavigator {
	
	public static final String ID = VDFCommonNavigatorView.class.getCanonicalName();
	
	
	@Override
	public void createPartControl(Composite aParent) {
		
		super.createPartControl(aParent);
		hookClickCommand();

		
	}
	
	/**
	 * 
	 * 
	 */
	private void hookClickCommand() {
		
		
		super.getCommonViewer().addSelectionChangedListener(new ISelectionChangedListener() {

			@Override
			public void selectionChanged(SelectionChangedEvent event) {

				IHandlerService handlerService = (IHandlerService) getSite()
						.getService(IHandlerService.class);
				try {
					handlerService.executeCommand(
							VDFCommonNavigatorHandler.ID,
							null);
				} catch (Exception ex) {
					throw new RuntimeException(
							VDFCommonNavigatorHandler.class.getCanonicalName());
				}

			}
		});

		super.getCommonViewer()
				.addSelectionChangedListener(new ISelectionChangedListener() {

					@Override
					public void selectionChanged(SelectionChangedEvent event) {
						IHandlerService handlerService = (IHandlerService) getSite()
								.getService(IHandlerService.class);
						try {
							handlerService
									.executeCommand(
											VDFCommonNavigatorHandler.ID,
											null);
						} catch (Exception ex) {
							throw new RuntimeException( VDFCommonNavigatorHandler.ID +
									" not found");
						}

					}
				});

	}
	

}
